package com.yxzx.ebs.controller;


import com.yxzx.common.YxzxResult;
import com.yxzx.ebs.entity.vo.EbsVideoInfoForm;
import com.yxzx.ebs.service.EbsVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author kongfuzi
 * @since 2020-07-31
 */
@Api(tags = "课时管理")
@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/eduservice/video")
public class EbsVideoController {
    @Autowired
    private EbsVideoService videoService;

    @ApiOperation("新增课时信息")
    @PostMapping
    public YxzxResult save(
            @ApiParam(name = "form", value = "课时对象",required = true)
            @RequestBody EbsVideoInfoForm form){
        videoService.saveVideoInfo(form);
        return YxzxResult.ok();
    }

    @ApiOperation("根据ID查询课时信息")
    @GetMapping("{id}")
    public YxzxResult getById(@ApiParam(name = "id", value = "课时ID", required = true)
                              @PathVariable String id){
        EbsVideoInfoForm videoInfoForm = videoService.getVedioInfoById(id);
        return YxzxResult.ok().data("item",videoInfoForm);
    }

    @ApiOperation("更新课时信息")
    @PutMapping("updateVideo")
    public YxzxResult updateVideo(
            @ApiParam(name = "form",value = "课时基本信息", required = true)
            @RequestBody EbsVideoInfoForm form){
        videoService.updateVideoInfo(form);
        return YxzxResult.ok();
    }

    @ApiOperation("删除课时信息")
    @DeleteMapping("{id}")
    public YxzxResult removeById(@ApiParam(name = "id",value = "课时ID",required = true)
                                 @PathVariable String id){
        boolean b = videoService.removeVideoById(id);
        return b ? YxzxResult.ok() : YxzxResult.error();
    }
}

